import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

import { InitService } from 'app/public/serve/init/init.service';
import { HintsService } from 'app/public/serve/hints/hints.service';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import {Service} from '../../../server/server';
declare var $: any;
@Component({
  selector: 'app-pushed-edit',
  templateUrl: './pushed-edit.component.html',
})
export class PushedEditComponent implements OnInit {
    @Input() details: any;
    @Output() onSubmit = new EventEmitter<void>();
    @Output()
    editOutput: EventEmitter<any> = new EventEmitter();
    constructor(
        public initService: InitService,
        private request: CudTableService,
        private hintsService: HintsService,
        private server:Service
    ) { }

    ngOnInit() {
    }

    /**
     * 修改
     * @param info
     */
    _onSubmit(info) {
        this.request
            .postRequest(this.server.baseUrl + 'Service/ThemeWords/updateThemeTable', info)
            .then(res=> {
                this.editOutput.emit(res.result_code);
                if(res.result_code == '0000') {
                    this.onSubmit.emit();
                }
                this.hintsService._operationHints(res.message, res.result_code);
                this._init();
                return
            })
            .catch(err=> {
                this.hintsService._operationHints('error', 'error');
                this._init();
                return
            })
    }
    /**
     * 初始化弹窗
     */
    private _init() {
        this.initService._init();
        $('#edit').modal("hide");
    }

}
